package com.qingyun.student.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qingyun.common.dto.Result;
import com.qingyun.student.entity.Student;
import com.qingyun.student.mapper.StudentMapper;
import com.qingyun.student.service.IStudentService;
import com.qingyun.common.util.UserHolder;
import com.qingyun.student.vo.StudentInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 学生表 服务实现类
 * </p>
 *
 * @author your_name
 * @since 2025-08-23
 */
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements IStudentService {
    @Autowired
    private StudentMapper studentMapper;
    @Autowired
    private UserHolder userHolder;
    @Override
    public Result studentInfo(String token, String keyword) {
        Long teacherId = userHolder.getUserId();
        if (teacherId == null) {
            return Result.fail("用户未登录或Token失效");
        }
        List<StudentInfoVO> userDTOS = studentMapper.studentInfo(teacherId, keyword);
        if (userDTOS.isEmpty()) {
            return Result.fail("暂无学生信息");
        }
        return Result.ok(userDTOS);
    }
}
